<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>state(状态)精简</title>
  <!-- react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- react扩展库支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 1.ES6转ES5；2.jsx转js -->
  <script src="../js/babel.min.js"></script>
</head>

<body>
  <div id="test"></div>
  <script type="text/babel">
    class Weather extends React.Component {
      // 类中可以直接用以下写法
      state = {
        isHot: true
      }
      // 自定义方法--赋值语句形式
      changeWeather = () => {
        // 箭头函数修改this指向为实例对象
        this.setState({
          isHot: !this.state.isHot
        })
      }
      render() {
        return (
          <h1 onClick={this.changeWeather} >今天天气{this.state.isHot ? '炎热' : '寒冷'}</h1>
        )
      }
    }
    ReactDOM.render(<Weather />, document.getElementById('test'))
  </script>
</body>

</html>